package liecai_class.day09;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * x++
 * ++x
 * x--
 * --x
 */
public class Demo03 {
    private static AtomicInteger x = new AtomicInteger(0);
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<100000;i++){
                    x.getAndIncrement();
//                    x.incrementAndGet();
//                    x.getAndDecrement();
//                    x.decrementAndGet();
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<100000;i++){
                    while(!x.compareAndSet(x.get(), x.get()+1)){
                    }
                }
            }
        }).start();
    }
}
